package com.powernode.feign;

import com.powernode.dto.CategoryDto;
import com.powernode.dto.ProductDto;
import com.powernode.dto.Result;
import com.powernode.validation.UpdateGroup;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;
import java.util.List;

/**
 * 商品微服务的远程调用接口
 **/
@FeignClient(name = "pn-mall-pms",fallbackFactory = FeignPMSFallBack.class,path = "/pms")
public interface PMSFeign {

    @GetMapping("/admin/products/{productId}")
    Result<ProductDto> getProductById(@PathVariable("productId") Long productId);

    @GetMapping("/admin/categories/{categoryId}")
    Result<CategoryDto> getCategoryById(@PathVariable("categoryId") Long categoryId);

    @GetMapping("/app/products/listByIds")
    Result<List<ProductDto>> listProductsByIds(@RequestParam("productIds") List<Long> productIds);

    @GetMapping("/app/categories/listByLevel")
    Result<List<CategoryDto>> listCategoriesByLevel(@RequestParam("level") Integer level);

    @PutMapping
     Result edit(@RequestBody  ProductDto productDto);

    /**
     * 扣减库存

     */
    @PutMapping("/app/products/stock/decr/{productId}/{num}")
    Result decrStock(@PathVariable("productId") Long productId, @PathVariable("num") @Min(1) Integer num);

    /**
     * 增加库存

     */
    @PutMapping("/app/products/stock/incr/{productId}/{num}")
    Result incrStock(@PathVariable("productId") Long productId, @PathVariable("num") @Min(1) Integer num);
}
